﻿package foli
{
	import foli.Album;
	import foli.AlbumEvent;
	import foli.Foto;
	
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Cube;
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.materials.utils.MaterialsList;	
				
	public class Line extends DisplayObject3D
	{		
		static var width: int = 1000;
		static var height: int = 30;
		static var depth: int = 5;
		
		public var album: Album = null;
		
		public function Line( a: Album )
		{			
			super();
		
			// store a reference to the originating album
			album = a;
			
			// register to get informed about new fotos
			a.addEventListener(AlbumEvent.FOTO_ADDED, this.handleFotoAdded);			
						
			// load fotos
			a.loadFotoList();
						
			// create gfx
			this.addChild( createVisual() );
		}			
		
		private function handleFotoAdded( e: AlbumEvent )
		{			
			addSlab( new Slab(e.foto) );
		}
		
		private function addSlab( s: Slab )
		{
			// move down the line a bit
			s.x = (Slab.width+2*1)*this.numChildren - width*0.5;
			s.z = -10;						
			
			addChild(s);
		}
		
		private function createVisual(): DisplayObject3D
		{
			var materials: MaterialsList = new MaterialsList(
																{
																	all:	new ColorMaterial(0x333333)
																} 
															);
			
			var c: Cube = new Cube( materials, width, depth, height, 2 ) ;			
			
			return c;
		}
	}
	
}